<?php $culture = $sf_user->getCulture() ?>
<script type="text/javascript">
    
    _images = new Array();
    _text = new Array();
    _titles = new Array();
    _links = new Array();
    
    <?php foreach($univ_news as $k => $one){ ?>
        _images.push('<?php $image = get_resized_image(609, 260, sfConfig::get('sf_upload_dir')."/university_news_$culture/".$one['image_'.$culture], false, true); echo $image; $images[] = $image ?>');
        <?php if($k == 0) {$first_image = $image;} ?>
        _text.push('<?php $str1 = str_replace("\r",'',$one['text_'.$culture]); $str2 = str_replace("\n",'',nl2br(strip_tags($str1))); echo truncate_text($str2,300,'...',true) ?>');
        _titles.push('<?php echo $one['title_'.$culture] ?>');
        _links.push('<?php echo url_for('@university_news?id='.$one['id']) ?>');
    <?php } ?>
</script>
<?php if(!empty($images)){?>
<?php foreach($images as $one){ ?>
<img src="<?php echo $one ?>" style="display:none"/>
<?php } ?>
<?php } ?>
<div class="main_slider_wrapper">
    <div class="slider_left">
            <div id="facebook_hover" style="position: absolute; z-index: 10; left: 551px; top: 12px;display: none; width: 31px; background-color: #0a71b3; height: 32px;"></div>
            <div id="twitter_hover" style="position: absolute; z-index: 10; left: 551px; top: 52px;display: none; width: 31px; background-color: #019AD2; height: 32px;"></div>
            <div id="email_hover" style="position: absolute; z-index: 10; left: 551px; top: 92px;display: none; width: 31px; background-color: #fdf3b2; height: 32px;"></div>
        <div class="social">
                <div onmouseout="document.getElementById('facebook_hover').style.display = 'none'" onmouseover="document.getElementById('facebook_hover').style.display = 'block'" style="margin-left: 5px; margin-top: 4px;cursor:pointer; display: block; width: 31px;  height: 32px;"></div>
                <div onmouseout="document.getElementById('twitter_hover').style.display = 'none'" onmouseover="document.getElementById('twitter_hover').style.display = 'block'" style="margin-left: 5px; margin-top: 4px;cursor:pointer; margin-top: 9px; display: block; width: 31px; height: 31px;"></div>
                <div onmouseout="document.getElementById('email_hover').style.display = 'none'" onmouseover="document.getElementById('email_hover').style.display = 'block'" style="margin-left: 5px; margin-top: 4px;cursor:pointer; margin-top: 9px; display: block; width: 31px; height: 31px;"></div>
        </div>
        <img id="bgimg" src="<?php echo $first_image ?>"/>
        <img id="bgimg2" src="<?php echo $first_image ?>" style="display:none"/>
    </div>
    <?php if ($sf_user->isAuthenticated()) include_component('user', 'home_logged_in'); else include_component('user', 'home_logged_out'); ?>
    <div class="clear"></div>
</div>
<?php if($univ_news_count > 0){ ?>
<script type="text/javascript">
    
    preloaded_images = new Array();

    function preload_image(image_file){
        preloaded_images.push(new Image());
        preloaded_images[preloaded_images.length-1].src = image_file;
    }
    
    image_path = '';/*'<?php echo public_path("/uploads/university_news_$culture/") ?>';*/

    
    $('#bgimg').attr('src',_images[0]);
    $('#univ_news_title a').html(_titles[0]);
    $('#univ_news_title a').attr('href',_links[0]);
    $('#univ_news_text').html(_text[0]);
    
    images_count = <?php echo $k+1 ?>;
  
    index = 1;
    timeout = 8000;

    function change_image(){
        fade_image();
        index++;
        if(index == images_count) index=0;
        setTimeout(change_image, timeout);
    }


    function fade_image(){
        if ($('img#bgimg').css('display') == 'none'){
            $('img#bgimg').attr('src',image_path+_images[index]);
            $('#univ_news_title a').html(_titles[index]);
            $('#univ_news_title a').attr('href',_links[index]);
            $('#univ_news_text').html(_text[index]);
        }
        else{
            $('img#bgimg2').attr('src',image_path+_images[index]);
            $('#univ_news_title a').html(_titles[index]);
            $('#univ_news_title a').attr('href',_links[index]);
            $('#univ_news_text').html(_text[index]);
        }
    }

    if (window.addEventListener){
        window.addEventListener('load', _post_load_univ_slider, false); 
    } else if (window.attachEvent){
        window.attachEvent('onload', _post_load_univ_slider);
    }
    
    function _post_load_univ_slider(){
        setTimeout(change_image,timeout);
        $('img#bgimg2').load(function(){
            $('img#bgimg2').fadeIn(3000);
            $('img#bgimg').fadeOut(3000);
        });

        $('img#bgimg').load(function(){
            $('img#bgimg').fadeIn(3000);
            $('img#bgimg2').fadeOut(3000);
        });
    }
    

</script>
<?php } ?>


<div class="_3_buttons">
    <div class="start_exploring">
        <?php //$obj = ContentTable::getInstance()->getBySlug('news-related') ?>
        <?php $obj = ContentTable::getInstance()->find(1) ?>
        <div class="title"><?php echo is_object($obj) ? $obj->getTitle() : '' ?></div>
        <div class="text"><?php echo is_object($obj) ? $obj->getBrief() : '' ?></div>
        <div class="link"><a href="<?php echo is_object($obj) ? url_for('@show_content?slug='.$obj->getSlug()) : '' ?>"><?php echo __('Start exploring >>') ?></a></div>
    </div>
    <div class="stay_updated">
        <?php //$obj = ContentTable::getInstance()->getBySlug('stay-updated') ?>
        <?php $obj = ContentTable::getInstance()->find(2) ?>
        <div class="title"><?php echo is_object($obj) ? $obj->getTitle() : '' ?></div>
        <div class="text"><?php echo is_object($obj) ? $obj->getBrief() : '' ?></div>
        <div class="link"><a href="<?php echo is_object($obj) ? url_for('@show_content?slug='.$obj->getSlug()) : ''?>"><?php echo __('Learn more >>') ?></a></div>
    </div>
    <div class="the_golden_rule">
        <?php //$obj = ContentTable::getInstance()->getBySlug('the-golden-rule') ?>
        <?php $obj = ContentTable::getInstance()->find(3) ?>
        <div class="title"><?php echo is_object($obj) ? $obj->getTitle() : '' ?></div>
        <div class="text"><?php echo is_object($obj) ? $obj->getBrief() : '' ?></div>
        <div class="link"><a href="<?php echo is_object($obj) ? url_for('@show_content?slug='.$obj->getSlug()) : ''?>"><?php echo __('Know more >>') ?></a></div>
    </div>
    <div class="clear"></div>
</div>

<?php include_component('main','home_shelves') ?>